package lib.login;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import jdbc.JdbcPort;

//查询用户名和密码是否存在以及是否与数据库相匹配
public class loginCheck {
	public boolean LoginCheck(String uid, String password) throws Exception {
		boolean returnValue = false;
		String sql = "SELECT * FROM libuser";
		Connection conn = null;
		Statement stmt = null;
		ResultSet rs = null;
 
		try {
			conn = JdbcPort.getConnection();
			stmt = conn.createStatement();
			rs = stmt.executeQuery(sql);
			while (rs.next()) {
				String uID = rs.getString("uid");
				String passWord = rs.getString("pswd");
				if (uID.equals(uid) && passWord.equals(password)) {
					//   如果用户名和密码都和数据库的一样，就返回true
					returnValue = true;
					break;
				}
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return returnValue;
	}
	
	public int GetUserType(String uid)throws Exception{
		int usertype=0;
		String sql="SELECT * FROM libuser where uid=?";
		System.out.println(uid);
		JdbcPort p=new JdbcPort();
		ResultSet rs=p.execQuery(sql, new Object[] {uid});
		String ustatus="";
		while(rs.next()) {
			ustatus=rs.getString("ustatus");
		}
		System.out.println(ustatus);
		if(ustatus.equals("管理员")) {
			usertype=1;
		}
		System.out.println(usertype);
		return usertype;
	}
	

}
